<template>
	<view class="product-item" @click="navToDetailPage(item)">
		<view class="image-wrapper">
			<image :src="item.pic" mode="aspectFill"></image>
		</view>
		<view class="txt">
			<text class="title clamp">{{item.title}}</text>
			<text class="title2">{{item.subTitle}}</text>
			<view class="hor-txt">
				<text class="price">￥{{item.price}}</text>
				<text class="time" v-show="showTime">{{item.createTime | formatDateTime}}</text>
			</view>
		</view>
	</view>
</template>

<script>
import { formatDate } from '@/utils/date';

export default {
	name:"product-item-row",
	props: {
		// 列表数据
		item: {
			type: Object,
			default () {
				return {
					pic: "",
					title: "",
					subTitle: "",
					price: 0
				};
			}
		},
		// 是否显示时间
		showTime: {
			type: Boolean,
			default: false
		},
	},
	data() {
		return {
			
		};
	},
	filters: {
		formatDateTime(time) {
			if (time == null || time === '') {
				return 'N/A';
			}
			let date = new Date(time);
			return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
		},
	},
	methods: {
		//详情
		navToDetailPage(item) {
			uni.navigateTo({
				url: `/pages/product/product?sku=${item.sku}`
			})
		},
	}
}
</script>

<style lang="scss">
	
.product-item {
	display: flex;
	flex-direction: row;
	width: 100%;
	padding-bottom: 40upx;
}

.image-wrapper {
	width: 30%;
	height: 250upx;
	border-radius: 20upx;
	overflow: hidden;

	image {
		width: 100%;
		height: 100%;
		opacity: 1;
	}
}

.txt {
	width: 70%;
	display: flex;
	flex-direction: column;
	padding-left: 40upx;
	
	.title {
		font-size: $uni-font-size-lg;
		color: $uni-text-color-dark;
		line-height: 80upx;
	}
	
	.title2 {
		font-size: $uni-font-size-sm;
		color:$uni-text-color-light;
		line-height: 40upx;
		height: 80upx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
	}
	
	//水平显示文本
	.hor-txt{
		display: flex;
		justify-content: space-between;
		line-height: 80upx;
		
		.price {
			font-size: $uni-font-size-lg;
			color: $uni-text-color-red;
		}
		
		.time {
			font-size: $uni-font-size-sm;
			color: $uni-text-color-dark;
		}
	}
	
}	
</style>
